package mylab.thread;

public class BusyThread implements Runnable{
	
	public static int counter=0;
	private String name;
	
	public BusyThread(String name)
	{
		this.name=name;
	}
	
	public void run()
	{
		int i=10000;
		while(i>0)
		{
			BusyThread.counter++;
			i--; //System.out.println(Thread.currentThread().getName()+" is adding 1");
		}
		System.out.println(this.name+": "+BusyThread.counter);
	}
	
	
	public static void main(String args[]) throws InterruptedException
	{
		Thread t1 = new Thread(new BusyThread("Thread 1"));
		Thread t2 = new Thread(new BusyThread("Thread 2"));
		
		t1.start();
		t2.start();
		System.out.println("This is printed after thread 1 and thread 2 are started.");
		//Thread.sleep(5000);
		while(t2.isAlive() || t1.isAlive())
		{
			
		}
		
		System.out.println("Counter is: " + BusyThread.counter);
		
	}

}
